package my.jwds.p169;

public class MajorityElement {

    public static void main(String[] args) {
        MajorityElement o = new MajorityElement();
        System.out.println(o.majorityElement(new int[]{2,3,4,5,6,1,1,1,1,1,1,1}));
    }


    public int majorityElement(int[] nums) {
        int count = 0;
        int temp = 0;
        for (int num : nums) {
            if (count == 0){
                temp = num;
            }
            if (temp == num){
                count++;
            }else{
                count--;
            }
        }
        return temp;
    }
}
